function appointmentSubmit() {
  var StudentNum = $('#StudentNum').val();
  var School = $('#School option:selected').val();
  var Activity = $('#Activity option:selected').val();
  var AppointmentDate = $('#AppointmentDate option:selected').text();
  var Content = $('#content').val();
  var UserQQ = $('#StudentQQ').val();
  var MobilePhone = $('#StudentPhone').val();
  var Name = $('#StudentName').val();
  if(StudentNum == '' || School == '' || UserQQ == '' || MobilePhone == '' || Name == '' || Activity == '' || Content == '') {
    alert('请填写必填字段！');
    return false;
  }
  var reg = /^[0-9]{11}$/
  if(!reg.test(MobilePhone)) {
    alert('手机号码有误！')
    return false
  }
  reg = /^[0-9]{6,12}$/
  if(!reg.test(UserQQ)) {
    alert('QQ有误！')
    return false
  }
  reg = /^[0-9]{7,14}$/
  if(!reg.test(StudentNum)) {
    alert('学号有误！')
    return false
  }
  $('#AppointmentSubmit').attr('disabled','disabled');
  $.ajax({
    url: '/Appointment/',
    type: 'POST',
    dataType: 'json',
    data: {
            StudentNum: StudentNum,
            School: School,
            AppointmentDate: AppointmentDate,
            DateID: Activity,
            Content: Content,
            UserQQ: UserQQ,
            MobilePhone: MobilePhone,
            Name: Name
          },
    success:function(callback){
      if(callback == "notLogin") {
        window.location = "/Accounts/login/";
      }
      else if(callback.substring(0,4) == "done"){
        alert("预约成功");
        window.location.reload();
        /*content = '<ul>' +
      		'<li>学号: ' + StudentNum + '</li>' +
          '<li>姓名：' + Name + '</li>' +
          '<li>学院：' + School + '</li>' +
      		'<li>预约日期：' + AppointmentDate + '</li>' +
          '<li>电话号码：' + MobilePhone + '</li>' +
    			'<li>QQ：' + UserQQ + '</li>' +
          '<li>维修内容：' + Content + '</li>' +
      		'<li>队列次序：' + callback.substring(4) + '</li>' +
      	   '</ul>';
        $('#appointment_done').append(content);*/
      }
      else {
        alert(callback);
      }
      $('#AppointmentSubmit').attr('disabled',false);
    }
  });
}

function AddTime() {
  var StartTime = $('#StartTime').val();
  var activityAbstract = $('#activityAbstract').val();
  var EndTime = $('#EndTime').val();
  var Limit = $('#Limit').val();
  if(StartTime == '' || EndTime == '' || Limit == '') {
    alert("输入格式有问题，请重新输入！");
    return false;
  }
  $('#AddTime').attr('disabled','disabled');
  $.ajax({
    url: '/AddTime/',
    type: 'POST',
    dataType: 'json',
    data: {
            StartTime: StartTime,
            EndTime: EndTime,
            Limit: Limit,
            activityAbstract: activityAbstract,
          },
    success:function(callback){
      if(callback == "notLogin") {
        window.location = "/Accounts/login/";
      }
      else {
        alert('成功添加');
        content = '<ul><li>简介：' + activityAbstract + '</li>' +
        '<li>开始时间：' + StartTime + '</li>' +
  			'<li>结束时间：' + EndTime + '</li>' +
  			'<li>报名人数：0</li>' +
  			'<li>人数限制：' + Limit + '</li>' +
  			"<li><button id=" + callback + " class='deleteTime form-sumbit pull-right'>删除</button></li></ul>";
        $('#date_done').append(content);
        $('.deleteTime').click(function() {
          if(confirm('确定删除？')) {
          DateID = $(this).attr('id');
          ul = $(this).parent().parent();
          $.ajax({
            url: '/DeleteTime/',
            type: 'POST',
            dataType: 'json',
            data: {
                    DateID: DateID
                  },
            success:function(callback){
              if(callback == "notLogin") {
                window.location = "/Accounts/login/";
              }
              else if(callback == "done"){
                ul.remove();
              }
            }
          });
          }
        });
        $('.finishActivity').click(function() {
          if(confirm('确定完成？')) {
            DateID = $(this).attr('id');
            ul = $(this).parent().parent();
            $.ajax({
              url: '/FinishActivity/',
              type: 'POST',
              dataType: 'json',
              data: {
                      DateID: DateID
                    },
              success:function(callback){
                if(callback == "notLogin") {
                  window.location = "/Accounts/login/";
                }
                else if(callback == "done"){
                  ul.remove();
                }
              }
            });
            window.location.reload();
          }
        });
      }
      $('#AddTime').attr('disabled',false);
    }
  });
}

$(document).ready(function() {


  $('.deleteTime').click(function() {
    if(confirm('确定删除？')) {
    DateID = $(this).attr('id');
    ul = $(this).parent().parent();
    $.ajax({
      url: '/DeleteTime/',
      type: 'POST',
      dataType: 'json',
      data: {
              DateID: DateID
            },
      success:function(callback){
        if(callback == "notLogin") {
          window.location = "/Accounts/login/";
        }
        else if(callback == "done"){
          ul.remove();
        }
      }
    });
    }
  });
  $('.finishActivity').click(function() {
    if(confirm('确定完成？')) {
    DateID = $(this).attr('id');
    ul = $(this).parent().parent();
    $.ajax({
      url: '/FinishActivity/',
      type: 'POST',
      dataType: 'json',
      data: {
              DateID: DateID
            },
      success:function(callback){
        if(callback == "notLogin") {
          window.location = "/Accounts/login/";
        }
        else if(callback == "done"){
          ul.remove();
        }
      }
    });
    window.location.reload();
    }
  });
  $('.finishAppointment').click(function() {
    if(confirm('确定完成？')) {
    StudentNum = $(this).attr('id');
    ul = $(this).parent().parent();
    $.ajax({
      url: '/finishAppointment/',
      type: 'POST',
      dataType: 'json',
      data: {
              StudentNum: StudentNum
            },
      success:function(callback){
        if(callback == "notLogin") {
          window.location = "/Accounts/login/";
        }
        else if(callback == "done"){
          ul.remove();
        }
        else {
          alert('error');
        }
      }
    });
    window.location.reload();
    }
  });
});
